package com.ting.template.core.common.exception;

import org.springframework.util.StringUtils;

public class AbeyException extends RuntimeException {

	private static final long serialVersionUID = -1L;

	/**
	 * 错误码
	 */
	private AbeyErrorCode revenueErrorCode;
	
	/**
	 * 错误描述
	 */
	private String message;

	/**
	 * 扩展
	 */
	private String extension;
	private String currentAgentId;

	public AbeyException() {
	}

	public AbeyException(AbeyErrorCode revenueErrorCode) {
		this.revenueErrorCode = revenueErrorCode;
		this.message = revenueErrorCode.getMsg();
	}

	public AbeyException(String message) {
		this.message =message;
	}
	public AbeyException(String message, String currentAgentId) {
		this.message =message;
		this.currentAgentId =currentAgentId;
	}

	public AbeyException(AbeyErrorCode revenueErrorCode, Throwable cause) {
		super(cause);
		this.revenueErrorCode = revenueErrorCode;
		this.message = revenueErrorCode.getMsg();
	}

	public AbeyException(String message, Throwable cause) {
		super(message, cause);
	}

	public AbeyException(AbeyErrorCode revenueErrorCode, String message) {
		// super(message);
		this.message = message;
		this.revenueErrorCode = revenueErrorCode;
	}

	public AbeyException(AbeyErrorCode revenueErrorCode, String message, Throwable cause) {
		super(message, cause);
		this.revenueErrorCode = revenueErrorCode;
	}

	public AbeyErrorCode getrevenueErrorCode() {
		// 返回自定义错误描述信息
		String message = this.getMessage();
		if (!StringUtils.isEmpty(message)) {
			this.revenueErrorCode.setMsg(message);
		}
		return revenueErrorCode;
	}

	public void setrevenueErrorCode(AbeyErrorCode revenueErrorCode) {
		this.revenueErrorCode = revenueErrorCode;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}
	
	public String getExtension() {
		return extension;
	}

	public void setExtension(String extension) {
		this.extension = extension;
	}

	public String getCurrentAgentId() {
		return currentAgentId;
	}

	public void setCurrentAgentId(String currentAgentId) {
		this.currentAgentId = currentAgentId;
	}

	@Override
	public String toString() {
		String clazz = getClass().getName();
		String message = getLocalizedMessage();
		return new StringBuilder("AbeyException:[")
				.append("clazz: " + clazz + ",")
				.append("message: " + message+",")
				.append("revenueErrorCode:").append(revenueErrorCode)
				.append("]").toString();
	}
}
